package utils;

import java.util.Iterator;
import java.util.Set;

import org.openqa.selenium.WebDriver;

public class OperatorUtil {
    //1 打开链接
    public static void open(WebDriver driver, String url) {
        driver.get(url);
    }

    //2.切换到最新的窗口
    public static WebDriver switchToNewWindow(WebDriver driver) {
        //得到当前句柄
        String currentWindow = driver.getWindowHandle();
        //得到所有窗口的句柄
        Set<String> handles = driver.getWindowHandles();
        //排除当前窗口的句柄，则剩下是新窗口
        Iterator<String> it = handles.iterator();
       while (it.hasNext()) {
            if (currentWindow == it.next()) continue;
            driver.switchTo().window(it.next());
        }
        return driver;
    }

    public static void waitTime(int time) {
        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}